<?php
namespace Common\Models;
use Common\BaseModel;
class FWalletsAmountLog extends BaseModel
{
    public $res;
    public $expire;

    public function initialize()
    {
        parent::initialize();
        $this->setSource('f_wallets_amount_log');
    }


    public function admin_get_list($params=[]){
        $page = $params['page'] ? intval($params['page']) : 1;
        $size = $params['limit'] ? intval($params['limit']) : 10;
        if ($page > 0) {
            $page = ($page - 1) * $size;
        }
        $conditions="u.id>0";
        if(isset($params['phone']) && !empty($params['phone'])){
            $conditions .= " AND u.phone='{$params['phone']}'";
        }
        $sql="SELECT al.*,u.phone,u.invite_code,u.nickname FROM `f_wallets_amount_log` as al
left join f_users as u on al.user_id = u.id
where $conditions
order by al.id desc
limit $page,$size";
        $items = $this->getDI()->get('dbMaster')->fetchAll($sql);

        $sql_count="SELECT count(al.id) as total FROM `f_wallets_amount_log` as al
left join f_users as u on al.user_id = u.id
where $conditions
order by al.id desc";
        $count = $this->getDI()->get('dbMaster')->fetchOne($sql_count);
        $get_list['items'] = $items;
        $get_list['total'] = (isset($count['total']) && !empty($count['total'])) ? (int)$count['total'] : 0;
        return $get_list;
    }


    public function get_list($params){
        $page = intval($params['page']);
        $size = intval($params['page_size']);
        if ($page > 0) {
            $page = ($page - 1) * $size;
        }
        $conditions="user_id={$params['user_id']}";
        $get_list = $this->find(array(
            'conditions'=>$conditions,
            'order'=>'created_at desc',
            'limit'=>$size,
            'offset'=>$page,
        ))->toarray();
        return $get_list;
    }

}
